* **************************************************************************** *
* Sierra Leone - Social Signaling and Childhood Immunization                   *
* Reference Groups for Social Signaling                                        *
* **************************************************************************** *
/*
** PURPOSE:      Generate Tables:
				1.) Who is concerned about your child's vaccination? 


*/
* **************************************************************************** *
* **************************************************************************** *


	use  "${Replicate_SocialSignals_dtaInter}/Endline_Survey_Data.dta", clear

	* Merge in the ANC treatment status:
	merge m:m clinic  using  "${Replicate_SocialSignals_dtaInter}/MasterData_PilotClinics.dta", gen(ANCtreat)


	* Label the treatment variable:
	lab var treat3   "Signal at 4"
	lab var treat4   "Signal at 5"
	lab var treat2   "Uninformative Bracelet"


	* ----------------------------------------------------------------------------
	* Label all variables used in the table:

	lab var concerned_people_1 "Father of the child"
	lab var concerned_people_2 "Family members"
	lab var concerned_people_4 "Nurse/CHW"
	lab var concerned_people_3 "Community members"


	* --------------------------------------------------------------------------
	* Demean control variables 

	tab     arm_anc, gen(anc)

	foreach control in anc2 anc3 anc4  {
		sum  `control' if intervention_arm==1, detail
		gen  `control'_dm = `control' - `r(mean)'
	}

	tab     education_cat, gen(educ)

	local   ControlVars = " mother_age_w01 educ2 educ3 farm  birth2 birth3 birth4 birth5 "

	foreach control of local  ControlVars  {
		summ `control'  if intervention_arm==1, detail
		gen  `control'_dm = `control' - `r(mean)'
	}


	* ----------------------------------------------------------------------------
	* Table generation 
	
	local   ControlVars = " mother_age_w01_dm educ2_dm educ3_dm farm_dm birth2_dm birth3_dm birth4_dm birth5_dm "
	local   ANC_dm      = " anc2_dm anc3_dm anc4_dm "

	local   OutcomeVars = " concerned concerned_people_1 concerned_people_2 concerned_people_4 concerned_people_3"

	eststo clear
	foreach outcomeVar of local OutcomeVars  {
		areg   `outcomeVar'  treat3 treat4 treat2  `ControlVars'    `ANC_dm', absorb(strata) vce(bootstrap , reps(${RepsNum}) seed(${seed}) cluster(clinic))
		eststo
		test   treat3 = treat2
		estadd scalar treat2_treat3 = r(p)
		test   treat3 = treat4
		estadd scalar treat3_treat4 = r(p)
		test   treat2 = treat4
		estadd scalar treat2_treat4 = r(p)
		test   treat2 treat3 treat4
		estadd scalar bracelets     = r(p)
		estadd local Obs            = "`e(N)'"
		estadd scalar C_mean        = _b[_cons]
		eststo m_`outcomeVar'
		}

	esttab  ///
	m_concerned m_concerned_people_1 m_concerned_people_2   ///
	m_concerned_people_4 m_concerned_people_3               ///
	using "${Replicate_SocialSignals_ATables}/Table_Concerned_raw.tex",        ///
	prehead("\begin{tabular}{l*{6}{c}} \toprule \\"                   ///
	"                                                          & \multicolumn{5}{c}{\textbf{Who is concerned about your child's vaccinations?}}  \\"   ///
	"\multicolumn{1}{l}{\textbf{\textbf{Dependent Variable:}}} & \multicolumn{1}{c}{\textbf{Anyone concerned}} & \multicolumn{1}{c}{\textbf{Father of child}} & \multicolumn{1}{c}{\textbf{Family member}} & \multicolumn{1}{c}{\textbf{Nurse/CHW}} & \multicolumn{1}{c}{\textbf{Community member}} \\")          ///
	scalars("C_mean       Control Group mean"                             ///
	"Obs          Observations"                                   ///
	"treat2_treat3 \(S_{4}\) \(>\) 0: p(UI = S4)"                 ///
	"treat2_treat4 \(S_{5}\) \(>\) 0: p(UI = S5)"                 ///
	"treat3_treat4 p(S4 = S5)"                                    ///
	"bracelets Joint F-Test")                                     ///
	substitute(\(S\_{4}\) \(S_{4}\)  \(S\_{5}\) \(S_{5}\))                ///
	keep(_cons treat3 treat4 treat2)                                      ///
	varlabels(_cons "Control Group mean")                                 ///
	sfmt(3) ${StarsOpt}  nomtitles                                        ///
	addnotes("") label b(3) se(3)  nobaselevels noconstant noobs          ///
	nolines posthead("\midrule") postfoot("\bottomrule \end{tabular}") tex  ///
	replace

	filefilter "${Replicate_SocialSignals_ATables}/Table_Concerned_raw.tex"      ///
	"${Replicate_SocialSignals_ATables}/Table_Concerned_Controls.tex", from("[1em]") to(" ") replace
	erase	   "${Replicate_SocialSignals_ATables}/Table_Concerned_raw.tex"





* **************************************************************************** *
* End of the Do file !!!
* **************************************************************************** *
